package net.jacqeush.mini.rpc.client.listener;

import io.netty.channel.ChannelFuture;
import net.jacqeush.mini.rpc.cache.ConnectCache;
import net.jacqeush.mini.rpc.client.RpcConnectManager;


import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

/**
 * @author Jacquesh
 * @version 1.0
 * @date 2020/10/16 0:32
 */
public class ChannelCloseListener implements  ChannelListener {
    @Override
    public void operationComplete(ChannelFuture future) throws Exception {
        future.channel().eventLoop().schedule(new Runnable() {
            @Override
            public void run() {
               ConnectCache.getInstance().clearConnected();
               RpcConnectManager
                       .getInstance()
                       .connectAsync((InetSocketAddress) future.channel().remoteAddress());
            }
        } ,3, TimeUnit.SECONDS);
    }
}
